/**
 * Project  : Looker
 * Package  : net.freestu.looker.common
 * File     : Category.java
 * Author   : solosky < solosky772@qq.com >
 * Date     : Aug 21, 2009
 * Modified : Aug 21, 2009
 * License  : Apache License 2.0 
 */
package net.freestu.looker.common;

import net.freestu.looker.monitor.AbstractPaging;
import net.freestu.looker.monitor.CommonPaging;
import net.freestu.looker.monitor.NewsMetaListManager;
import net.freestu.looker.monitor.OffsetPaging;
import net.freestu.looker.util.HashUtils;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 *  栏目
 * @author  solosky
 * @version v1.0
 */
public class Category
{
	/**
	 * 栏目编号
	 */
	private String hash;
	
	/**
	 * 栏目标题
	 */
	private String title;
	
	
	/**
	 * 栏目配置
	 */
	private Configuration configuration;
	
	/**
	 * 所属站点
	 */
	private Site site;
	
	/**
	 * 分页对象
	 */
	private AbstractPaging paging;
	
	/**
	 * 临时新闻列表管理器
	 */
	private NewsMetaListManager listManager;
	
	/**
	 * 构造函数
	 * @param conf 配置节点
	 */
	public Category(Configuration conf, Site site)
	{
		this.configuration = conf;
		this.site   = site;
		this.title  = configuration.getString("title");

		String pagingType = site.getConfig().getString("list.pagingType");
		String id		  = configuration.getString("id");
		String url        = site.getConfig().getString("site.url")
							+site.getConfig().getString("list.url").replace("{categoryid}", id);
		
		if(pagingType.equals("offset"))
			this.paging = new OffsetPaging(url);
		else
			this.paging = new CommonPaging(url);
		this.hash        = HashUtils.shortHash(this.paging.getURL(1));
		this.listManager = new NewsMetaListManager(this.hash);
	}
	

	public String toString()
	{
		return new ToStringBuilder(this)
				.append("hash",hash)
				.append("url",paging.getURL(1))
				.append("title",title)
				.toString();
	}

	public String getHash()
    {
    	return hash;
    }

	public String getTitle()
    {
    	return title;
    }

	public Configuration getConfiguration()
    {
    	return configuration;
    }

	public Site getSite()
    {
    	return site;
    }

	public NewsMetaListManager getListManager()
    {
    	return listManager;
    }

	public AbstractPaging getPaging()
    {
    	return paging;
    }
	
	
	
}
